package org.unittest.taxi;

import java.math.BigDecimal;

public class Taxi {
    public static final int STARTING_DISTANCE = 2;
    public static final double STARTING_FARE = 6.00;
    public static final double SHORT_DISTANCE_FARE = 0.8;
    public static final int SHORT_DISTANCE = 8;
    public static final double WAITING_RATE = 0.25;
    public static final double FAR_DISTANCE_FARE = 0.5;
    private TaxiPrinter taxiPrinter;


    public Taxi(TaxiPrinter taxiPrinter) {
        this.taxiPrinter = taxiPrinter;
    }

    public Taxi() {
    }


    public BigDecimal calculate(double distance, double waitingTime) {
        if (distance < 0) {
            throw new IllegalArgumentException("cannot input distance as negative parameters");
        }

        if (waitingTime < 0) {
            throw new IllegalArgumentException("cannot input waiting time as negative parameters");
        }

        double waitingFare = WAITING_RATE * waitingTime;

        if (distance <= STARTING_DISTANCE) {
            return BigDecimal.valueOf(STARTING_FARE + waitingFare);
        }

        if (distance <= SHORT_DISTANCE) {
            return BigDecimal.valueOf(STARTING_FARE + (distance - STARTING_DISTANCE) * SHORT_DISTANCE_FARE + waitingFare);
        }

        if (distance > SHORT_DISTANCE) {
            return BigDecimal.valueOf(STARTING_FARE + (distance - STARTING_DISTANCE) * SHORT_DISTANCE_FARE * (1 + FAR_DISTANCE_FARE) + waitingFare);
        }

        return BigDecimal.valueOf(0.00);
    }


    public void submit(int distance, int waitingTime) {
        BigDecimal fare = calculate(distance, waitingTime);
        taxiPrinter.print(distance, waitingTime, fare);
        pay(fare);
    }

    public void pay(BigDecimal fare) {
        throw new UnsupportedOperationException();
    }


}
